var rootPath = getRootPath();

//dataStr日期字符串
//dayCount 要增加的天数
function dateAddDays(dataStr,dayCount) {
    var strdate=dataStr; //日期字符串
    var isdate = new Date(strdate.replace(/-/g,"/"));  //把日期字符串转换成日期格式
    isdate = new Date((isdate/1000+(86400*dayCount))*1000);  //日期加1天
    var pdate = isdate.getFullYear()+"-"+(isdate.getMonth()+1)+"-"+(isdate.getDate());   //把日期格式转换成字符串

    return pdate;
}

$(document).ready(function(){
	var userId = 84;
	var carId = 78;
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/insurance/selectLastInsure?userId='+userId+'&carId='+carId, 
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){

			var userId = ''; 	
			var registNo = ''; 	
			var modelName = ''; 	
			var carId = ''; 	
			var lastInsureDate = '';
			var nextInsureDate = '';
			
			$.each(resultData,function(lastMaintainIndex,lastMaintainObj){

				userId = lastMaintainObj.userId;
				registNo = lastMaintainObj.registNo;
				modelName = lastMaintainObj.modelName;
				carId = lastMaintainObj.carId;
				lastInsureDate = lastMaintainObj.lastInsureDate;
				nextInsureDate = dateAddDays(lastInsureDate,364);
				
			});

			$("#registNo").html(registNo);
			$("#carName").html(modelName);
			$("#lastInsureDate").html(lastInsureDate);
			$("#nextInsureDate").html(nextInsureDate);
			$("#userId").val(userId);
			$("#carId").val(carId);
		}
	});
})